<%--
  Created by IntelliJ IDEA.
  User: 王鹏飞
  Date: 2020/7/21
  Time: 10:35
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt"%>
<jsp:include page="../common/menu.jsp" />

<html>
<head>
    <title>单车月结算</title>
</head>

<script src="<%=basePath%>js/tools.js"></script>
<body>
<div class="layui-tab">
    <ul class="layui-tab-title">
        <li class="layui-this">单车月结算</li>
    </ul>
    <div class="layui-tab-content">
        <table class="layui-hide" id="backUser" lay-filter="backUser"></table>
    </div>
</div>

<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="addUser">生成单车月结</button>
    </div>
</script>

<script type="text/html" id="startTime">
    {{ dateFormat(d.startTime) }}
</script>

<script type="text/html" id="createTime">
    {{ dateFormat(d.createTime) }}
</script>

<script type="text/html" id="bar">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
</script>
</body>
</html>
<jsp:include page="../common/js.jsp" />
<div class="layui-form-item" id="show" style="display: none">
    <div class="layui-inline">
        <label class="layui-form-label">结算日期</label>
        <div class="layui-input-inline">
            <input type="text" id="settlementTime" name="settlementTime" value="" readonly="readonly" lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">车牌号码</label>
        <div class="layui-input-inline">
            <select name="vehicleNum" id="vehicleNumId" class="layui-input" lay-filter="vehicleNum">
                <option value="0">请选择车牌号码</option>
                <c:forEach var="vehicle" items="${vehicleInfos}">
                    <option value="${vehicle.vehicleNum }">${vehicle.vehicleNum }</option>
                </c:forEach>
            </select>
        </div>
    </div>
</div>

<script type="text/javascript">

    $('document').ready(function() {
        var layer = null;
        var laypage = null;
        var table = null;
        var form = null;
        layui.use([ "laypage", "layer", 'table' ,'laydate'], function() {
            layer = layui.layer;
            laypage = layui.laypage;
            table = layui.table;
            form = layui.form;
            laydate = layui.laydate;

            table.render({
                elem : '#backUser',
                url : '<%=basePath%>settlement/settlementList',
                id : 'backUser',
                height:650,
                toolbar : '#toolbar',
                cellMinWidth : 100,
                cols : [ [
                    {
                        field : 'id',
                        title : '编号',
                        width : '5%',
                        unresize : true,
                        sort : true
                    }
                    , {
                        field : 'vehicleNum',
                        title : '车牌号',
                        width : '10%',
                        unresize : true,
                        sort : true
                    }
                    , {
                        field : 'settlement',
                        width : '13%',
                        align : 'center',
                        title : '结算年月'
                    }
                    , {
                        field : 'totalMoney',
                        title : '总营业额',
                        width : '10%',
                        unresize : true
                    }
                    , {
                        field : 'totalKilometres',
                        title : '总公里数',
                        width : '10%',
                        sort : true
                    }
                    , {
                        field : 'totalAmount',
                        title : '费用总计',
                        width : '10%',
                        sort : true
                    }
                    , {
                        field : 'grossProfit',
                        title : '毛利润',
                        width : '10%',
                        sort : true
                    }
                    , {
                        field : 'fuelMoney',
                        title : '油费',
                        width : '10%',
                        sort : true
                    }
                    , {
                        field : 'bridgeMoney',
                        title : '过桥费',
                        width : '10%',
                        sort : true
                    }
                    , {
                        field : 'stopMoney',
                        title : '停车费',
                        width : '10%',
                        sort : true
                    }
                    , {
                        field : 'repairMoney',
                        title : '修理费',
                        width : '10%',
                        sort : true
                    }
                    , {
                        field : 'tireMoney',
                        title : '轮胎费',
                        width : '10%',
                        sort : true
                    }
                    , {
                        field : 'subsidizeMoney',
                        title : '车补贴',
                        width : '10%',
                        sort : true
                    }
                    , {
                        field : 'wages',
                        title : '工资',
                        width : '10%',
                        sort : true
                    }
                    , {
                        field : 'gpsMoney',
                        title : 'GPS费用',
                        width : '10%',
                        sort : true
                    }
                    , {
                        field : 'premium',
                        title : '保险费',
                        width : '10%',
                        sort : true
                    }
                    , {
                        field : 'loan',
                        title : '还贷',
                        width : '10%',
                        sort : true
                    }
                    , {
                        field : 'dividends',
                        title : '分红',
                        width : '10%',
                        sort : true
                    }
                    , {
                        field : 'otherMoney',
                        title : '其他',
                        width : '10%',
                        sort : true
                    }
                    , {
                        field : 'createTime',
                        title : '操作日期',
                        width : '10%',
                        templet : '#createTime',
                        sort : true
                    }
                    , {
                        field : 'remark',
                        title : '备注',
                        width : '12%',
                        unresize : true
                    }
                    , {
                        field : 'createBy',
                        title : '创建人',
                        width : '10%',
                        sort : true
                    }
                    , {
                        fixed:'right',
                        width:120 ,
                        align:'center',
                        toolbar:'#bar',
                        title:'操作'
                    }
                ] ],
                page : true
            });

            //头工具栏事件
            table.on('toolbar(backUser)', function(obj) {
                var checkStatus = table.checkStatus(obj.config.id);
                var data = checkStatus.data;
                switch(obj.event){
                    case 'addUser':

                        layer.open({
                            type : 1,//Layer提供了5种层类型。可传入的值有：0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）
                            title : '选择车牌信息',//标题
                            shade : 0.4,//遮罩透明度
                            content : $('#show'),
                            btn : ['确定','取消'],
                            scrollbar : false , // 屏蔽浏览器滚动条
                            yes : function (index) {//点击确定回调的内容
                                // 获取信息并跳转进行计算
                                var settlementTime = $("#settlementTime").val();
                                var vehicleNum = $("#vehicleNumId").val();
                                var syear = settlementTime.split("-")[0];
                                var smonth = settlementTime.split("-")[1];
                                var nowdate = new Date();
                                var year = nowdate.getFullYear();
                                var month = nowdate.getMonth()+1;

                                layer.msg(syear + " "+ smonth+ " "+ year+ " "+ month);
                                if(syear>nowdate.getFullYear() || smonth >= (nowdate.getMonth()+1)){
                                    layer.msg("不可选择的月份");
                                    return ;
                                }else if(vehicleNum==0){
                                    layer.msg("请选择车辆信息");
                                    return ;
                                }else{
                                    window.location.href="<%=basePath %>settlement/toAddSettlement?settlementTime="+settlementTime+"&vehicleNum="+vehicleNum;
                                }
                            },
                            btn2:function () {
                                layer.msg("no");
                                layer.closeAll();
                            }
                        });

                        break;
                };

            });
            laydate.render({
                elem : '#settlementTime',
                type : 'month',
                trigger : 'click'
            });


            //监听工具条
            table.on('tool(backUser)', function(obj){
                var data = obj.data;
                console.log(data)
                if(obj.event === 'edit'){
                    if(data.status == 1){
                        window.location.href="<%=basePath %>settlement/toEditSettlement?id="+data.id;
                    }else{
                        layer.msg('此状态不允许修改！');
                    }
                }else if(obj.event === 'del'){
                    if(data.status == 1){
                        window.location.href="<%=basePath %>dispatch/delDispatch?id="+data.id;
                    }else{
                        layer.msg('此状态不允许删除！');
                    }
                }
            });

        });
    });

    function changeStatus(str) {
        var typeName = new Map();
        typeName.set(1, '未审核-未收款');
        typeName.set(2, '已审核-未收款');
        typeName.set(3, '已完成-已收款');
        typeName.set(0, '已取消');
        return typeName.get(str);
    }
</script>